<?php
include_once "../lib/DAL/DonVi.php";
class DonViBLL{
    function __construct(){
        
    }
    
    function __destruct(){
        
    }
    
    function setDonViBLL($row){
        $donvi = new DonVi();
        $donvi->setdonvi($row['ma_donvi'],$row['ten_donvi'],$row['sdt_donvi'],$row['email_donvi'],$row['diadiem_donvi'],$row['maloai_donvi']);
        return $donvi;         
    }
    
	public function getDonViInfo($ma_donvi){
        $sql = "select * from tbl_donvi where ma_donvi ='".$ma_donvi."'";
        $row = mysql_fetch_array(mysql_query($sql));
       return $this->setDonViBLL($row);        
    }
	
    public function getListDonVi_Lienket(){
      $result = mysql_query("select * from tbl_donvi WHERE maloai_donvi='ttlk'");
      $arr_donvi= array();
      
      while($row = mysql_fetch_array($result)){
        $arr_donvi[] =  $this->setDonViBLL($row);
      }
      return $arr_donvi;
    }
    
    public function getListDonVi_Lienket_Canbo($ma_cb){
      $result = mysql_query("   Select * from tbl_donvi,tbl_donvi_cb
                                WHERE 	maloai_donvi='ttlk' 
                                AND	tbl_donvi.ma_donvi=tbl_donvi_cb.ma_donvi
                                AND	ma_cb='$ma_cb'");
      $arr_donvi= array();
      
      while($row = mysql_fetch_array($result)){
        $arr_donvi[] =  $this->setDonViBLL($row);
      }
      return $arr_donvi;
    }
    
    public function getDonVi_Lienket_Canbo($ma_cb){
      $result = mysql_query("Select  ma_donvi FROM tbl_donvi_cb WHERE ma_cb='$ma_cb' LIMIT 1");
      $kq=mysql_fetch_array($result);
        
      return $kq['ma_donvi'];
    }
    
}

?>